package com.mini.cn.goods.servlet.ws.common;

import com.mini.cn.goods.util.SHA1Utils;
import lombok.extern.slf4j.Slf4j;


/**
 * Created with IntelliJ IDEA.

 * User: fly
 * Date: 2020-02-11
 * Time: 10:35 上午
 */
@Slf4j
public class VerifyHelper {

    //约定好的key
    private static final String LINKKEY = "IloveDota";


    /**
     * 校验连接
     *
     * @param original
     * @param token
     * @return
     */
    public static boolean checkServiceLegal(String original, String token) {
        StringBuilder builder = new StringBuilder(original);
        builder.append(LINKKEY);
        String sign = SHA1Utils.sign(builder.toString());
        return token.equals(sign);
    }


    /**
     * 鉴权验证
     *
     * @param original
     * @param token
     * @param key
     * @return
     */
    public static boolean checkPushLegal(String original, String token, String key) {
        StringBuilder builder = new StringBuilder(original);
        builder.append(key);
        String sign = SHA1Utils.sign(builder.toString());
        return token.equals(sign);
    }

    public static void main(String[] agrs) {
        //String str = "AUUID_238dba187796ab6bbaccda20c0fff8e9652197ba_koudai1582887401389IloveDota";
        String str = "ykp_koudai1582887401389IloveDota";
        System.out.println(SHA1Utils.sign(str));
    }
}
